// lib/app/core/di/dependency_injection.dart

import 'package:get/get.dart';
import 'package:location_test/app/data/repositories/settings_repository_impl.dart';
import 'package:location_test/app/domain/repositories/settings_repository.dart';

import '../../data/datasources/local/storage_util.dart';
import '../../data/datasources/platform/battery_service.dart';
import '../../data/datasources/platform/bluetooth_service.dart';
import '../../data/datasources/platform/location_service.dart';
import '../../data/datasources/remote/mqtt_service.dart';
import '../../data/repositories/device_repository_impl.dart';
import '../../domain/repositories/device_repository.dart';

/// 统一注册应用所需的服务与仓库，便于 GetX 管理依赖。
class DependencyInjection {
  /// 应在应用启动时调用，一般位于 main.dart。
  static void init() {
    // --- 注册基础服务 ---
    Get.lazyPut<StorageService>(() => StorageService(), fenix: true);
    Get.lazyPut<LocationService>(() => LocationService(), fenix: true);
    Get.lazyPut<BatteryService>(() => BatteryService(), fenix: true);
    Get.lazyPut<BluetoothService>(() => BluetoothService(), fenix: true);
    Get.lazyPut<MqttService>(() => MqttService(), fenix: true);

    // --- 注册仓库实现 ---
    Get.lazyPut<IDeviceRepository>(
      () => DeviceRepositoryImpl(
        Get.find<LocationService>(),
        Get.find<BatteryService>(),
        Get.find<BluetoothService>(),
      ),
      fenix: true,
    );

    Get.lazyPut<ISettingsRepository>(
      () => SettingsRepositoryImpl(Get.find<StorageService>()),
      fenix: true,
    );
  }
}
